<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="所属企业" prop="companyId">
        <el-select
          v-model="queryParams.companyId"
          filterable
          clearable
          placeholder="请选择所属企业"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in companyList"
            :key="item.id"
            :label="item.companyName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bussiness:project:overview:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="projectList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="所属企业" align="center" prop="companyName" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目地址" align="center" prop="address" />
      <el-table-column label="负责人" align="center" prop="linkMain" />
      <el-table-column label="负责人电话" align="center" prop="linkTel" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['bussiness:project:overview:query']"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <div class="dialog-content">
        <el-descriptions direction="vertical" :column="2" border>
          <el-descriptions-item label="所属企业"
            >kooriookami</el-descriptions-item
          >
          <el-descriptions-item label="项目名称"
            >18100000000</el-descriptions-item
          >
          <el-descriptions-item label="项目简介" :span="2">
            <el-tag size="small">学校</el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="项目地址" :span="2"
            >苏州市</el-descriptions-item
          >
          <el-descriptions-item label="负责人">范忠杰</el-descriptions-item>
          <el-descriptions-item label="负责人电话">范忠杰</el-descriptions-item>
        </el-descriptions>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProjectOverview,
  getProjectOverview,
  listCompany,
} from "@/api/bussiness/projectOverview";

export default {
  name: "ProjectOverview",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        address: null,
        linkMain: null,
        linkTel: null,
        companyId: null,
        info: null,
        logo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //企业列表
      companyList: [],
    };
  },
  created() {
    this.getList();
    this.listCompany();
  },
  methods: {
    listCompany() {
      listCompany().then((res) => {
        this.companyList = res.data;
      });
    },
    /** 查询项目列表 */
    getList() {
      this.loading = true;
      listProjectOverview(this.queryParams).then((response) => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        projectName: null,
        address: null,
        linkMain: null,
        linkTel: null,
        companyId: null,
        info: null,
        logo: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "bussiness/project/export",
        {
          ...this.queryParams,
        },
        `project_${new Date().getTime()}.xlsx`
      );
    },
    handleView(row) {
      this.reset();
      const id = row.id || this.ids;
      getProjectOverview(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "项目详情";
      });
    },
  },
};
</script>
